package net.hn.hnms.biz.indicator.controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import net.hn.hnms.biz.api.safety.monitor.model.FireIndicatorVo;
import net.hn.hnms.biz.indicator.entity.ChartAnaliseVo;
import net.hn.hnms.biz.indicator.entity.IndicatorScoreVo;
import net.hn.hnms.biz.indicator.link.MineLinkService;
import net.hn.hnms.biz.indicator.service.DwsMineMathematicalModelService;
import net.hn.hnms.sys.common.core.domain.R;
import net.hn.hnms.sys.common.satoken.config.AutoSetMineCode;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.math.BigDecimal;
import java.util.List;
import java.util.Map;

/**
 * @author 智呈物联 nzw
 * @date 2022/10/17
 */
@RestController
@RequestMapping("safety/IndicatorScore")
@Api(value = "安全态势评分", tags = {"安全态势评分"})
public class IndicatorScoreController {

    private MineLinkService mineLinkService;

    private DwsMineMathematicalModelService mineMathematicalModelService;

    @Autowired(required = false)
    public void setMineLinkService(MineLinkService mineLinkService, DwsMineMathematicalModelService mineMathematicalModelService) {
        this.mineLinkService = mineLinkService;
        this.mineMathematicalModelService = mineMathematicalModelService;
    }


    @GetMapping("/score")
    @ApiOperation("安全态势评分")
    public R<IndicatorScoreVo> score() {
        IndicatorScoreVo indicatorScoreVo = new IndicatorScoreVo();
        Map<String, Object> dustMap = mineLinkService.dustIndicator();
        Map<String, Object> dustVo = (Map<String, Object>) dustMap.get("data");
        indicatorScoreVo.setDustPersonnel(new BigDecimal(dustVo.get("personnel") + ""));
        indicatorScoreVo.setDustEnvironment(new BigDecimal(dustVo.get("environment") + ""));
        indicatorScoreVo.setDustManage(new BigDecimal(dustVo.get("manage") + ""));
        indicatorScoreVo.setDustDevice(new BigDecimal(dustVo.get("device") + ""));
        indicatorScoreVo.setDustComprehensive(new BigDecimal(dustVo.get("comprehensive") + ""));
        indicatorScoreVo.setDustProblems((List<Map<String, Object>>) dustVo.get("problems"));

        R<FireIndicatorVo> fireMap = mineLinkService.fireIndicator();
        FireIndicatorVo fireIndicatorVo = fireMap.getData();
        indicatorScoreVo.setFireInternal(fireIndicatorVo.getInternal());
        indicatorScoreVo.setFireExternal(fireIndicatorVo.getExternal());
        indicatorScoreVo.setFirePersonnel(fireIndicatorVo.getPersonnel());
        indicatorScoreVo.setFireManage(fireIndicatorVo.getManage());
        indicatorScoreVo.setFireComprehensive(fireIndicatorVo.getComprehensive());
//        indicatorScoreVo.setFireProblems((List<Map<String,Object>>) fireIndicatorVo.get("problems"));

//        Map<String,Object> floodMap = mineLinkService.floodIndicator();
//        Map<String,Object> floodVo = (Map<String,Object>)floodMap.get("data");
//        indicatorScoreVo.setFloodInrush(new BigDecimal(floodVo.get("inrush")+""));
//        indicatorScoreVo.setFloodElectrical(new BigDecimal(floodVo.get("electrical")+""));
//        indicatorScoreVo.setFloodHydrology(new BigDecimal(floodVo.get("hydrology")+""));
//        indicatorScoreVo.setFloodDrainage(new BigDecimal(floodVo.get("drainage")+""));
//        indicatorScoreVo.setFloodComprehensive(new BigDecimal(floodVo.get("comprehensive")+""));
//        indicatorScoreVo.setFloodProblems((List<Map<String,Object>>) floodVo.get("problems"));
        //20230627 由于水害预警-风险管理 里面返回的评分参数修改,所有为了保持一直而进行修改
        //远程获取水害预警-风险管理
        Map<String, Object> floodMap = mineLinkService.floodIndicator();
        Map<String, Object> floodVo = (Map<String, Object>) floodMap.get("data");
        //获取 水害-人员
        indicatorScoreVo.setFloodPersonnel(new BigDecimal(floodVo.get("personnel") + ""));
        //获取 水害-环境
        indicatorScoreVo.setFloodEnvironment(new BigDecimal(floodVo.get("environment") + ""));
        //获取 水害-管理
        indicatorScoreVo.setFloodManage(new BigDecimal(floodVo.get("manage") + ""));
        //获取 水害-设备
        indicatorScoreVo.setFloodDevice(new BigDecimal(floodVo.get("device") + ""));
        //获取综合得分
        indicatorScoreVo.setFloodComprehensive(new BigDecimal(floodVo.get("comprehensive") + ""));
        //获取扣分问题集合
        indicatorScoreVo.setFloodProblems((List<Map<String, Object>>) floodVo.get("problems"));


        Map<String, Object> gasMap = mineLinkService.gasIndicator();
        Map<String, Object> gasVo = (Map<String, Object>) gasMap.get("data");
        indicatorScoreVo.setGasPersonnel(new BigDecimal(gasVo.get("personnel") + ""));
        indicatorScoreVo.setGasEnvironment(new BigDecimal(gasVo.get("environment") + ""));
        indicatorScoreVo.setGasManage(new BigDecimal(gasVo.get("manage") + ""));
        indicatorScoreVo.setGasDevice(new BigDecimal(gasVo.get("device") + ""));
        indicatorScoreVo.setGasComprehensive(new BigDecimal(gasVo.get("comprehensive") + ""));
        indicatorScoreVo.setGasProblems((List<Map<String, Object>>) gasVo.get("problems"));
        return R.ok(indicatorScoreVo);
    }


    @ApiOperation("瓦斯评分趋势")
    @GetMapping("gasIndicatorTrend")
    @AutoSetMineCode
    public R<List<ChartAnaliseVo>> gasIndicatorTrend(String mineCode) {
        return R.ok(mineMathematicalModelService.gasIndicatorTrend(mineCode));
    }

}
